<?
function tags_update($pid,$value) {
    global $db;
    $pid = $db->sqlint($pid);
    $db->query0("delete from tags where project_id = $pid");
    
    foreach (explode(",",$value) as $v) {
        $v = strtolower($v);
        $v = preg_replace("/[^a-zA-Z0-9]/","",$v);
        if (!strlen($v)) { continue; }
        $v = $db->sqlstring($v);
        $db->query0("insert into tags (project_id,value) values ($pid,$v)");
    }
}

function tags_get($pid) {
    global $db;
    $pid = $db->sqlint($pid);
    $r = $db->query("select * from tags where project_id = $pid");

    $v = array();
    foreach ($r as $e) {
        $v[] = $e["value"];
    }
    return $v;
}

function tags_cloud($r) {
    global $topurl;
    $pre = "";
    echo "<div style='text-align:center;'>";
    foreach ($r as $e) {
        $s = intval(10+min(24,sqrt($e["cnt"])*24/5));
        $s2 = intval($s/2);
        echo "<a href='$topurl/tags/{$e["value"]}' style='font-size:$s;margin-left:{$s2}px;margin-right:{$s2}px;'>{$e["value"]}</a> ";
        $pre = ", ";
    }
    echo "</div>";
}

?>